<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>3.axios.create</title>
</head>
<body>
<button id="btn1">发送axios请求1</button>
<button id="btn2">发送axios请求2</button>

<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/1.10.1/jquery.js"></script>

<script type="text/javascript">
    const  data ={
        username: "Alice",
        age:12,
        gender: 'girl'
    }
    /*
    * 指定了默认的配置之后后续直接使用的axios都会使用默认配置
    * */
    axios.defaults.baseURL="http://127.0.0.1/axios";

    $("#btn1").click(()=>{
        axios.get("get",{params:data})
        .then(
            response =>{
                console.log(response.data)
            },
            error =>{
                console.log(error)
            }
        )
    });

    /*如果某个axios要使用自己独特的URL要重新创建一个*/
    const newAxios = axios.create({
       baseURL:"http://127.0.0.1/demo"
    });

    $("#btn2").click(()=>{
        newAxios.get("/get",{params:data})
        .then(
            response =>{
                console.log(response.data)
            },
            error =>{
                console.log(error)
            }

        )
    })

</script>
</body>
</html>